home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / Rxil.lha / Rxil / src / cleanup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-30  |  2.4 KB  |  119 lines

  1. /* cleanup.c */
  2.  
  3. /*        Copyright © 1989 by Donald T. Meyer, Stormgate Software
  4.  *        All Rights Reserved
  5.  */
  6.  
  7.  
  8.  
  9. #include "rxil.h"
  10.  
  11.  
  12.  
  13. /* NAME
  14.  *        RxilCleanup
  15.  *
  16.  * SYNOPSIS
  17.  *        RxilCleanup( rdef )
  18.  *
  19.  *        struct RxilDef *rdef;
  20.  *
  21.  * FUNCTION
  22.  *        Cleanup the entire ARexx port.
  23.  *        This will set the Abort flag, then wait till all ARexx program
  24.  *        invocations which we have made are completed.
  25.  *        At this time, all ARexx message ports will be closed.
  26.  *        Any remaining RxilInvocation structures which were allocated
  27.  *        via RxilCreateRxi() and not yet deleted via RxilDeleteRxi()
  28.  *        will be cleaned up and freed.
  29.  *        The ARexx library will be closed.
  30.  *        Finally, the RexxDef structure itself will be freed.
  31.  *
  32.  * INPUTS
  33.  *        rdef = pointer to the RxilDef structure returned by a call to
  34.  *            RxilInit().
  35.  *
  36.  * RESULT
  37.  *        None
  38.  *
  39.  * SIDES
  40.  *
  41.  * HISTORY
  42.  *        01-Aug-89    Creation.
  43.  *
  44.  * BUGS
  45.  *
  46.  * SEE ALSO
  47.  *        RxilInit(), RxilPending()
  48.  */
  49.  
  50. void RxilCleanup( struct RxilDef *rdef )
  51. {
  52.     if( rdef == NULL )
  53.     {
  54.         return;
  55.     }
  56.  
  57.  
  58.     /* Deal with any commands or functions which we have launched that
  59.      * have not yet returned
  60.      */
  61.  
  62.     while( RxilPending() == TRUE )    /* till all replys are back */
  63.     {
  64.         /* Setting this flag will cause the routines which check the
  65.          * rexx port to refuse to accept further commands.
  66.          */
  67.         rdef->Abort = TRUE;
  68.  
  69.         Wait( rdef->SigBit );
  70.  
  71.         RxilCheckPort();
  72.     }
  73.  
  74.  
  75.     /* Now that all invocation messages are back, we can do a default
  76.      * handling of each return.  The structures are then deleted.
  77.      *
  78.      * Since the variable 'invocations' contains a pointer to the
  79.      * first RxilInvocation structure on the list, we can use it
  80.      * directly to walk the list.  When we delete a structure, the
  81.      * deletion routine will put the next structure's address into
  82.      * 'invocations' (if there is a next structure).
  83.      */
  84.      while( rdef->Invocations )    /* scan list */
  85.     {
  86.         if( rdef->Invocations->State == RXIL_STATE_RETURNED )
  87.         {
  88.             RxilCleanupReturn( rdef->Invocations );
  89.         }
  90.  
  91.         RxilDeleteRxi( rdef->Invocations );
  92.     }
  93.  
  94.  
  95.     /* Close and remove the ports */
  96.  
  97.     if( rdef->PublicPort )
  98.     {
  99.         RxilDeletePort( rdef->PublicPort );
  100.         rdef->PublicPort = NULL;
  101.     }
  102.  
  103.     if( rdef->SecretPort )
  104.     {
  105.         RxilDeletePort( rdef->SecretPort );
  106.         rdef->SecretPort = NULL;
  107.     }
  108.  
  109.     /* Close the library */
  110.     if( RexxSysBase )
  111.     {
  112.         CloseLibrary( (struct Library *)RexxSysBase );
  113.         RexxSysBase = NULL;
  114.     }
  115.  
  116.     FreeMem( rdef, sizeof(struct RxilDef) );
  117. }
  118.  
  119.